home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 February: Tool Chest / Dev.CD Feb 94.toast / New System Software Extensions / QuickDraw™ GX v1.0ß2 / Sample Code / Printing Samples / Printer Drivers… / ImageWriterLQ / ChooserSupport.c < prev    next >
Encoding:
Text File  |  1993-09-13  |  8.4 KB  |  300 lines  |  [TEXT/MPS ]

  1. /*---------------------------------------------------------------------------
  2. FILENAME
  3.     ChooserSupport.c
  4.  
  5. DESCRIPTION
  6.     This file contains the C code for the PACK and LDEF routines used by the
  7.     Chooser when the ImageWriter LQ driver is selected in the Chooser.
  8.         
  9. COPYRIGHT
  10.     Copyright Apple Computer, Inc. 1992
  11.     All rights reserved. 
  12.     
  13. INTERFACE ROUTINES:
  14.     Device
  15.     LDEF
  16.  
  17. -------------------------------------------------------------------------------- */
  18.  
  19. // Include the standard Mac header files 
  20. #include "MacIncludes.h"
  21.  
  22. // Include the new QuickDraw GX graphics header files 
  23. #include <graphics routines.h>
  24.  
  25. // Include the required Printing Manager header files 
  26. #include <PrintingDrivers.h>
  27.  
  28. /*********************************************************************************
  29.  *                                         CONSTANTS                                                     *
  30.  *********************************************************************************/
  31.  
  32. // Chooser initialize message selector
  33. #define    initializeMsg            11
  34.  
  35. // Icon Suite support
  36.  
  37. #define    ttNone                    0x0000
  38. #define    ttDisabled                0x0001
  39. #define    ttOffline                0x0002
  40. #define    ttOpen                    0x0003
  41. #define    ttSelected                 0x4000
  42. #define    ttSelectedDisabled        (ttSelected + ttDisabled)
  43. #define    ttSelectedOffline        (ttSelected + ttOffline)
  44. #define    ttSelectedOpen            (ttSelected + ttOpen)
  45.  
  46. #define    ttLabel0                    0x0000
  47. #define    ttLabel1                    0x0100
  48. #define    ttLabel2                    0x0200
  49. #define    ttLabel3                    0x0300
  50. #define    ttLabel4                    0x0400
  51. #define    ttLabel5                    0x0500
  52. #define    ttLabel6                    0x0600
  53. #define    ttLabel7                    0x0700
  54.  
  55.  
  56. /*********************************************************************************
  57.  *                                    INLINE DECLARATIONS                                            *
  58. **********************************************************************************/
  59.  
  60. pascal OSErr PlotIconSuite(const Rect * theRect, short align, short iconTransform, Handle cIcon)
  61.     = {0x303C, 0x0603, 0xABC9};
  62.  
  63. pascal void OldDrawText(const void *textBuf,short firstByte,short byteCount)
  64.     = 0xA885; 
  65.  
  66.  
  67. /***************************************************************************************
  68. *                                         INTERFACE ROUTINES                                                     *
  69. ***************************************************************************************/                        
  70.  
  71.  
  72. /****************************************************************************************
  73.  
  74.                             Device
  75.                             
  76.     function:
  77.                 This routine is the interface routine for the Chooser PACK.  This is the
  78.                 routine the Chooser calls to perform the Chooser functions for the 
  79.                 ImageWriter LQ driver.
  80.                 
  81.     parameters:                
  82.                 message        specifies which Chooser function to perform    
  83.                 caller        equals 1; specifies the caller is the Chooser
  84.                 objName        name of the selected device
  85.                 zoneName        zone name for AppleTalk devices
  86.                 theList        the list of names
  87.                 p2                parameter used depending upon message value
  88.                 
  89.     returns:
  90.                 OSErr
  91.     
  92. ****************************************************************************************/
  93. pascal OSErr Device(    short         message, 
  94.                         short         caller, 
  95.                         StringPtr     objName,
  96.                         StringPtr    zoneName, 
  97.                         ListHandle    theList, 
  98.                         long        p2)
  99. {
  100.     
  101.     OSErr                anErr = noErr;
  102.     extern Str31    gDriverName;
  103.     extern gxJob    gJob;
  104.     StringPtr        pDriverName = &gDriverName;
  105.     gxJob            *pJob = &gJob;
  106.     
  107.     if (message == initializeMsg)        //    T => Chooser PACK should initialize itself; start up QuickDraw GX 
  108.     {
  109.         FCBPBRec    pb;
  110.  
  111.         // determine the name of the driver selected
  112.         pb.ioCompletion     = nil;
  113.         pb.ioNamePtr         = pDriverName;
  114.         pb.ioVRefNum         = 0;
  115.         pb.ioRefNum         = CurResFile();
  116.         pb.ioFCBIndx         = 0;
  117.         anErr = PBGetFCBInfo(&pb, false);
  118.  
  119.         // Now initialize QuickDraw GX
  120.         *pJob = nil;
  121.         if (anErr == noErr)
  122.         {
  123.             GXEnterGraphics();
  124.             anErr = GXGetGraphicsError(nil);
  125.             if (anErr == noErr)
  126.                 anErr = GXInitPrinting();
  127.         }
  128.     }
  129.         
  130.     // We let the system handle the device choosing for us
  131.     if (anErr == noErr)
  132.         anErr = GXHandleChooserMessage(pJob, pDriverName, message, caller, objName, zoneName, theList, p2);
  133.         
  134.     // Is it time to go away?
  135.     if ( (message == terminateMsg) && (p2 == terminateMsg) )
  136.     {
  137.         GXExitPrinting();
  138.         GXExitGraphics();
  139.     }
  140.  
  141.     return(anErr);
  142. }
  143. /* Device */
  144.  
  145.  
  146.  
  147. /****************************************************************************************
  148.  
  149.                             LDEF
  150.                             
  151.     function:
  152.                 This routine is the LDEF fro the Chooser PACK.  It handles drawing the device
  153.                 list contents.  The LDEF works in two modes:
  154.                     - if the first two characters of the cell are valid AppleTalk NBP names (ie, not ≈ ≈)
  155.                       then the LDEF is just a basic text LDEF
  156.                     - otherwise, it assumes the data is part of a PortListRec, which is
  157.                       a structure for icons with text underneath
  158.                             
  159.     parameters:                
  160.                 message        what operation to perform on the list    
  161.                 select        is this cell to be selected or not?
  162.                 theRect        rectangle of this cell, clipped to window
  163.                 theCell        which cell this is
  164.                 dataOffset    offset into data for this cell
  165.                 dataLen        length of data for this cell
  166.                 theList        the list to act upon
  167.                 
  168.     returns:
  169.                 None
  170.     
  171. ****************************************************************************************/
  172. pascal void LDEF(
  173.     short             message,
  174.     Boolean            select,
  175.     Rect            *theRect,
  176.     Cell            theCell,
  177.     short            dataOffset,
  178.     short            dataLen,
  179.     ListHandle    theList)
  180. {
  181.     #pragma unused (theCell, dataLen)
  182.  
  183.     gxPortListRec        theCellContents;
  184.     Rect                iconRect;
  185.     
  186.     switch (message)
  187.     {
  188.         case lDrawMsg:
  189.         case lHiliteMsg:
  190.         
  191.             // save the data to avoid locking things down
  192.             if (dataLen > sizeof(theCellContents) )
  193.                 dataLen = sizeof(theCellContents);
  194.             BlockMove(((*(**theList).cells) + dataOffset), &theCellContents, dataLen );
  195.             
  196.             // draw the cell as an icon, but only if we see our magic marker at the front
  197.             if ( (theCellContents.firstMarker == '≈') && (theCellContents.secondMarker == '≈') )
  198.             {
  199.                 // center the icon rect on the list with a top margin of 10 pixels
  200.                 iconRect.top = theRect->top + 10;
  201.                 iconRect.left = theRect->left + ((theRect->right - theRect->left) >> 1) - 16;
  202.                 iconRect.bottom = iconRect.top + 32;
  203.                 iconRect.right = iconRect.left + 32;
  204.                 
  205.                 
  206.                 // draw the icon
  207.                 if (theCellContents.iconSuiteHandle != nil)
  208.                     PlotIconSuite(&iconRect,
  209.                             ttNone, (select) ? ttSelected: ttNone,
  210.                             theCellContents.iconSuiteHandle);
  211.                             
  212.                 // Get the general area under the icon in which to draw the label
  213.                 iconRect.left = theRect->left + 2;
  214.                 iconRect.right = iconRect.left + (**theList).cellSize.h - 2;
  215.                 iconRect.top = iconRect.bottom + 2;
  216.                 iconRect.bottom = theRect->bottom;
  217.     
  218.                 // use a nice small font for the label            
  219.                 TextFont(applFont);
  220.                 TextSize(9);
  221.                 
  222.                 {
  223.                     short        labelWidth;
  224.                     short        rectWidth;
  225.                     short        labelHeight;
  226.                     FontInfo    theInfo;
  227.                 
  228.                     // Get rid of any text that was there before
  229.                     EraseRect(&iconRect);
  230.                     iconRect.top += 2;
  231.                     
  232.                     // compute the height of the label                    
  233.                     GetFontInfo(&theInfo);
  234.                     labelHeight = theInfo.ascent + theInfo.leading;
  235.                     
  236.                     // compute where to draw the text
  237.                     iconRect.bottom = iconRect.top + labelHeight;
  238.                     rectWidth = iconRect.right-iconRect.left;
  239.                     
  240.                     // truncate the string to fit within the box
  241.                     TruncString(rectWidth, theCellContents.iconName, smTruncEnd);
  242.                     
  243.                     // compute the new width of the string
  244.                     labelWidth = StringWidth(theCellContents.iconName);
  245.                     
  246.                     // center the string, draw it
  247.                     iconRect.left += (rectWidth >> 1) - (labelWidth >> 1);
  248.                     MoveTo(iconRect.left, iconRect.bottom);
  249.                     DrawString(theCellContents.iconName);
  250.                     
  251.                     if (select)
  252.                     {
  253.                         // compute right and lower edge of box bounding the text we just drew
  254.                         iconRect.right = iconRect.left + labelWidth;
  255.                         iconRect.bottom += theInfo.descent;
  256.                         
  257.                         // outset it, and invert it to select it
  258.                         InsetRect(&iconRect, -1, -1);
  259.                         BitClr(pHiliteBit, HiliteMode);
  260.                         InvertRect(&iconRect);
  261.                     }
  262.                 }
  263.                     
  264.                 TextFont(applFont);
  265.                 TextSize(0);
  266.             }
  267.             else
  268.             {
  269.                 // how boring!  It's only text
  270.                 FontInfo    theInfo;
  271.                 Rect        ourRect;
  272.                 
  273.                 // add a margin to the rectangle
  274.                 ourRect = *theRect;
  275.                 ourRect.left += 3;
  276.                 
  277.                 // erase the rectangle
  278.                 GetFontInfo(&theInfo);
  279.                 EraseRect(theRect);
  280.                 MoveTo(ourRect.left, ourRect.bottom - theInfo.descent);
  281.                 
  282.                     
  283.                 // those darn other languages!
  284.                 if (GetSysJust() == teJustRight)
  285.                     Move(ourRect.right-ourRect.left-TextWidth((Ptr) &theCellContents, 0, dataLen) , 0);
  286.                     
  287.                 OldDrawText((Ptr) &theCellContents, 0, dataLen);
  288.                 
  289.                 // if selected, invert it
  290.                 if (select)
  291.                     InvertRect(theRect);
  292.             }
  293.                 
  294.             break;
  295.             
  296.     } // switch
  297.         
  298. }
  299. /* LDEF */
  300.